<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 
        父组件传入的值，如果改变了，子组件会同步改变
        子组件不能去改变接收到的props的值的

        一定想改的，可以将props的值用于作为子组件data的初始值
       -->
      <h2>单向数据流 - {{ count }}</h2>
      <button @click="count++">btn</button>
      <child :count="count" :obj="obj" :name="name"></child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;
      const Child = {
        props: {
          count: Number,
          obj: Object,
          name: String,
        },
        data() {
          return {
            name2: this.name,
          };
        },
        template: `
          <div>这是child子组件</div>
          <p>count: {{ count }}</p>
          <button @click="count++">child-btn</button>
          <p>obj: {{ obj }}</p>
          <button @click="obj.a = 30">btn2</button>

          <hr />

          <p>name: {{ name2 }}</p>
          <button @click="name2 = 'lisi'">btn3</button>
        `,
      };

      const app = createApp({
        data() {
          return {
            count: 10,
            obj: {
              a: 3,
              b: 4,
            },
            name: "zhangsan",
          };
        },
        components: {
          Child,
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
